package com.xjj.servicejob.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sjy
 * @create 2022-10-24 10:55
 * 配置消息队列
 */
@Configuration
public class ConsumerConfig {
    /**
     * 声明交换机
     *
     * @return
     */
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("exchangeTopic");
    }

    /**
     * 声明队列
     *
     * @return
     */
    @Bean
    public Queue initJobSubmit() {
        return new Queue("initJobSubmit");
    }

    /**
     * 绑定队列到交换机
     *
     * @param queue
     * @param exchange
     * @return
     */
    @Bean
    public Binding bindingEmail(@Qualifier("initJobSubmit") Queue queue, TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("initJobSubmit");
    }

    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }
}
